Page({
  data:{
    userInfo:{},
    openId:"",
    admin:false
  },
  onGotUserInfo:function(e){
    const that = this
    wx.cloud.callFunction({
      name:"login",
    }).then(res=>{
      console.log("云函数调用成功")
      console.log(res);
      console.log(e);
        that.setData({
          openId:res.result.openid,
          userInfo: e.detail.userInfo
        })
        that.data.userInfo.openid = that.data.openId
        console.log("openId", that.data.openId)
        console.log("userInfo", that.data.userInfo)
        wx.setStorageSync("userInfo", that.data.userInfo)
    }).catch(res=>{
      console.log(res);
      console.log("云函数调用失败");

    })
  },
  // 跳转到个人信息页面
  goToPersonalInfo: function () {
    wx.navigateTo({
      url: '/pages/userInfo/userInfo',
    });
  },
  isAdmin: async function () {
    let res = await wx.cloud.callFunction({
      name: "is_admin"
    });
    console.log(res);
    return res.result;
  },
  onLoad:async function(options){
    this.isAdmin().then(res=>{
      this.setData({
        admin: res
      })
    })
    
    const ui = wx.getStorageSync('userInfo')
    this.setData({
      userInfo:ui,
      openId:ui.openid
    })
    console.log(ui);
  },
  goToEditDailySurvey:function(){
    wx.navigateTo({
      url:"/pages/editDailySurvey/editDailySurvey",
    });
  },
  goToEditUserInfoSurvey:function(){
    wx.navigateTo({
      url:"/pages/editUserInfoSurvey/editUserInfoSurvey",
    });
  }
})